1. Field of the Invention
The present invention relates to a method, system, and program for dispatching a method call.
2. Description of the Related Art
In the Java** runtime environment, which is implemented by a Java Virtual Machine (“JVM”), software components may be dynamically loaded by one or more class loaders. In Java, a software component is represented by one or more classes executed by the JVM. A class loader method takes a class name as an argument when called and returns a class object that is a runtime representation of the class. Certain class loaders may be used to load classes associated with facilities and components that are intended to be shared among different classes and certain other class loaders may be used to load application specific or other user-defined classes that are not shared. **Sun Microsystems and Java are trademarks of Sun Microsystems, Inc.
A component object can call another object using a local reference. The receiving object will attempt to process the call. A problem may arise if the calling and receiving objects were instantiated from classes loaded by different class loaders, and the call invoked by the calling object has parameters and/or return values with types loaded by the class loaders. In such case, an exception could be thrown if the receiving object attempts to recognize the type loaded in the caller's class loader as the type loaded in the receiver's class loader. This is because the types have different runtime identities. In Java, the runtime identity of a type is defined by the class name of the type and the class loader that loaded the type.
The Remote Method Invocation (RMI) protocol may be used to avoid the problem of a class mismatch. In RMI, when the calling object calls the method on the receiving object, any parameter serialized as a result of the call is annotated with the codebase associated with the parameter. The codebase is a set of Universal Resource Locators (URLs) from where the class files for the annotated objects can be located. According to the RMI protocol, the receiving object, upon receiving the method invocation, will use the codebase in the annotation to load the class if the class cannot be loaded by the receiving object's class loader or, if the receiving object's class loader can load a class having the same name, the receiving object would use such loaded class. Thus, with RMI, an exception is not thrown if there is a class mismatch, because, according to the RMI protocol, the receiving object will use the class, having the same name, loaded by the receiving object's class loader.